/*
* @Author: song
* @Description:物体移动到目标点
* @Date: 2024年04月18日 星期四 15:04:42
* @Modify:
*/

using System;
using TMPro;
using UnityEngine;

namespace SCore.Function.ScriptPipeline
{
    public struct SAGotoPosData
    {
        public Vector3 _startPos;
        public Vector3 _endPos;
        public Vector3 _midPos;
        public Transform _tran;
        public Func<Vector3, Vector3, Vector3, float, Vector3> _curveAction;
    }


    public class ScrpitPipelineAGotoPos : ScrpitPipelineAction
    {
        private SAGotoPosData _data;
        private float _opTime;

        public ScrpitPipelineAGotoPos(SAGotoPosData saGotoPosData) : base()
        {
            _data = saGotoPosData;
        }

        protected override bool Action(float dt)
        {
            _opTime += dt;
            var d = _data;
            if (d._tran == null)
            {
                return true;
            }

            d._tran.position = d._curveAction.Invoke(d._startPos, d._midPos, d._endPos, _opTime);
            bool finish = Vector3.Distance(d._tran.position, d._endPos) <= 0.2f;
            if (finish)
            {
                d._tran.position = d._endPos;
            }

            return finish;
        }
    }
}